package view
{
	import flash.display.*;
	import flash.text.TextField;
	import flash.events.Event;
	
	import model.BattlePx;
	
	/**
	 * -- BattleView --
	 * @desc	view to show battles
	 * @author	Aqua (built on 2011-11-09)
	 */
	public class BattleView extends BaseView
	{
		//--------------------//
		//     BattleView     //
		//--------------------//
		
		/**************************************************************************
		 * -- BattleView --
		 * @desc		constructor
		 * @param		main view object of this view class
		 *************************************************************************/
		public function BattleView(viewComponent:DisplayObjectContainer):void
		{
			super(viewComponent);
			
			_viewComponent.name = VIEW_NAME;
			_iconCharaList = [];
			_battlePx = getPx(BattlePx.NAME) as BattlePx;
			
			addAddCmd("txt_name_self",		add_txt_name_self);
			addAddCmd("txt_name_enemy",		add_txt_name_enemy);
			addAddCmd("txt_condition",		add_txt_condition);
			addAddCmd("txt_combination",	add_txt_combination);
			addAddCmd("txt_event",			add_txt_event);
			addAddCmd("img_icon_event",		add_img_icon_event);
			addAddCmd("img_icon_chara",		add_img_icon_chara);
			addAddCmd("img_chara",			add_img_chara);
		}
		
		/**************************************************************************
		 * -- onAdd --
		 * @desc		override to implement timer
		 *************************************************************************/
		public override function onAdd():void
		{
			super.onAdd();
			MovieClip(_viewComponent).addEventListener(Event.ENTER_FRAME, onFrame);
		}
		
		
		//------------------//
		//     Privates     //
		//------------------//
		
		//-- Add Handlers --//
		private function add_txt_name_self():void
		{
			TextField(_display).text = _battlePx.getMyName();
		}
		private function add_txt_name_enemy():void
		{
			TextField(_display).text = _battlePx.getEnemyName();
		}
		private function add_txt_condition():void
		{
			TextField(_display).text = _battlePx.getEvtCondition();
		}
		private function add_txt_combination():void
		{
			TextField(_display).text = _battlePx.getEvtCondition();
		}
		private function add_txt_event():void
		{
			var index:int;
			
			index = getIndex(_display);
			TextField(_display).text = _battlePx.getEvent(index);
		}
		private function add_img_icon_event():void
		{
			if (! _iconEvt)
			{
				_iconEvt = _display;
			}
		}
		private function add_img_icon_chara():void
		{
			var index:int;
			
			index = getIndex(_display);
			
			if (! _iconCharaList[index])
			{
				_iconCharaList[index] = _display;
			}
		}
		private function add_img_chara():void
		{
			
		}
		
		
		/**************************************************************************
		 * -- onFrame --
		 * @desc		update UI in every frame
		 * @param		(e) event information
		 *************************************************************************/
		private function onFrame(e:Event):void
		{
			if (_iconEvt)
			{
				// update icon position
			}
		}
		
		
		public static const VIEW_NAME	:String = "BattleView";
		public static const LAYER_INDEX	:int	= 2;
		
		private var _battlePx		:BattlePx;
		private var _iconEvt		:DisplayObject;
		private var _iconCharaList	:Array;
	}
	
}